﻿amplify.request.decoders.RegularData =
    function (data, status, xhr, success, error) {
        if (xhr.statusText === "success") {
            success(data);
        }
        else {
            toastr.error(xhr.responseText, "ERROR: " + xhr.statusText);
        }
    };

amplify.request.decoders.MessageResult =
    function (data, status, xhr, success, error) {
        if (xhr.statusText === "success") {
            if (data.Status == 0) {
                success(data.Content);
            }
            else if (data.Status == 1) { // Warning
                    toastr.warning(data.Message, "Warning: " + data.Status);
                    success(data.Content);
                } else if (data.Status == 2) { // Error 
                    toastr.error(data.Message, "ERROR: " + data.Status);
                    success(data.Content);
                }
                else {
                    toastr.error(data.Message, "ERROR: " + data.Status);
                }
        }
        else {
            toastr.error(xhr.responseText, "ERROR: " + xhr.statusText);
        }
    };


amplify.subscribe("request.error", function (settings, data, status) {
    toastr.error(data, "ERROR: " + status);
});

amplify.subscribe("request.before.ajax", function (settings, data, status) {
    //Start animation
    $("#AjaxProgressBar").show(500);
});

amplify.subscribe("request.complete", function (settings, data, status) {
    //Stop animation
    $("#AjaxProgressBar").hide(500);
});

DeixeiDomain.PagedResult = function (data) {
    var self = this;
    self.TotalPages = ko.observable(data.TotalPages);
    self.TotalCount = ko.observable(data.TotalCount);
    self.PageIndex = ko.observable(data.PageIndex);
    self.PageSize = ko.observable(data.PageSize);

    self.HasPreviousPage = ko.observable(data.HasPreviousPage);
    self.HasNextPage = ko.observable(data.HasNextPage);
    self.StartPage = ko.observable(data.StartPage);
    self.EndPage = ko.observable(data.EndPage);
    self.NextPage = ko.observable(data.NextPage);
    self.PreviousPage = ko.observable(data.PreviousPage);
}

DeixeiDomain.MessageResult = function (data) {
    var self = this;
    self.Status = ko.observable(data.Status);
    self.Message = ko.observable(data.Message);
}

$(function () {
    // Init. ProgressBar
    $("#AjaxProgressBar").hide();
});
